package com.example.community.list;

import com.example.community.dao.ParkingDao;
import com.example.community.model.Parking;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/parkingListServlet")
public class ParkingListServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Integer ys = null;
        if (req.getParameter("ys")==null){
            ys = 1 ; //当前页数
        }else {
            ys = Integer.parseInt(req.getParameter("ys"));
        }
        int shuju = 8; //每页显示数据个数
        ParkingDao parkingDao = new ParkingDao();
        List<Parking> parkings = parkingDao.fandLimit(ys,shuju);

        Integer totalPageNum = parkingDao.selectLimitCount(shuju);
        req.setAttribute("parkings",parkings);
        req.setAttribute("totalPageNum",totalPageNum);
        req.setAttribute("ys",ys);
        req.getRequestDispatcher("/WEB-INF/parkingManager/parkingList.jsp").forward(req,resp);
    }
}
